package cn.ubeta.b2c.settings;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import cn.ubeta.b2c.BuildConfig;
import cn.ubeta.b2c.R;
import cn.ubeta.b2c.common.AnalyseActivity;
import cn.ubeta.b2c.utils.ToastHelper;
import cn.ubeta.b2c.web.WebViewActivity;

/**
 * Created by denny on 16/9/6.
 */

public class AboutActivity extends AnalyseActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        onCreate(savedInstanceState, R.layout.activity_about);

        ((TextView) findViewById(R.id.tv_about_version)).setText("版本:" + BuildConfig.VERSION_NAME);

        findViewById(R.id.tv_goto_rate).setOnClickListener(this);
        findViewById(R.id.tv_share).setOnClickListener(this);
        findViewById(R.id.tv_private).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (R.id.tv_goto_rate == id) {
            gotoAppStore();
        } else if (R.id.tv_private == id) {
            String urlPrivate = "http://mayshijia.com/share/page/zhengce.html";
            String namePrivate = "隐私声明";
            WebViewActivity.gotoWebPage(this, namePrivate, urlPrivate, false);
        } else if (R.id.tv_share == id) {
            // TODO 分享应用
        }
    }

    /**
     * 去市场评分
     */
    private void gotoAppStore() {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } catch (Exception e) {
            ToastHelper.show("没有可以打分的应用商店，感谢支持！");
        }
    }

}
